%-------------------------------------------------------------------------
% Subroutine: Scatter plots showing shock contributions and housing boom size 
%
% Estimation Codes for State-Level Results in  
% Ben-David, Itzhak, Sebastian Weber, and Pascal Towbin 
% "Inferring Expectations from Observables: Evidence from the Housing Market" 
% Review of Economics and Statistics
% ------------------------------------------------------------------------ 

%% SCATTER CHARTS

% EXEPCTATION
y=squeeze(bustsize);
x=speccontrib;
corr=corrcoef(y,x);
R_squared=round(corr(1,2)^2,2);

pt(:,2)=y;
pt(:,1)=x;
figure('Name','Figure 8a: Expectation shock')
set(gcf, 'Name','Figure 8a: Expectation shock','NumberTitle','off') 
scatter(pt(:,1),pt(:,2)), hold on
lsline
labels = StateLab;    %'
text(pt(:,1), pt(:,2), labels, 'horizontal','left', 'vertical','bottom')
title({'Expectation shock contribution to boom', ['and size of bust in percent (R^2 = ' num2str(R_squared) ')']})
xlabel('Contribution of shock to price increase, 1996-2006') 
ylabel('Price drop 2012-2006') 
box on

% MORTGAGE RATE
y=squeeze(bustsize);
x=intcontrib;
corr=corrcoef(y,x);
R_squared=round(corr(1,2)^2,2);

pt(:,2)=y;
pt(:,1)=x;
figure('Name','Figure 8b: Mortgage rate shock')
set(gcf, 'Name','Figure 8b: Mortgage rate shock','NumberTitle','off') 
scatter(pt(:,1),pt(:,2)), hold on
lsline
labels = StateLab;    %'
text(pt(:,1), pt(:,2), labels, 'horizontal','left', 'vertical','bottom')
title({'Mortgage rate shock contribution to boom', ['and size of bust in percent (R^2 = ' num2str(R_squared) ')']})
xlabel('Contribution of shock to price increase, 1996-2006') 
ylabel('Price drop 2012-2006') 
box on

% DEMAND
y=squeeze(bustsize);
x=demandcontrib;
corr=corrcoef(y,x);
R_squared=round(corr(1,2)^2,2);

pt(:,2)=y;
pt(:,1)=x;
figure('Name','Figure 8b: Housing consumption shock')
set(gcf, 'Name','Figure 8b: Housing consumption shock','NumberTitle','off') 
scatter(pt(:,1),pt(:,2)), hold on
lsline
labels = StateLab;    %'
text(pt(:,1), pt(:,2), labels, 'horizontal','left', 'vertical','bottom')
title({'Housing consumption shock contribution to boom', ['and size of bust in percent (R^2 = ' num2str(R_squared) ')']})
xlabel('Contribution of shock to price increase, 1996-2006') 
ylabel('Price drop 2012-2006') 
box on

% Supply
y=squeeze(bustsize);
x=supplycontrib;
corr=corrcoef(y,x);
R_squared=round(corr(1,2)^2,2);

pt(:,2)=y;
pt(:,1)=x;
figure('Name','Figure 8b: Housing supply shock')
set(gcf, 'Name','Figure 8b: Housing supply shock','NumberTitle','off') 
scatter(pt(:,1),pt(:,2)), hold on
lsline
labels = StateLab;    %'
text(pt(:,1), pt(:,2), labels, 'horizontal','left', 'vertical','bottom')
title({'Housing supply shock contribution to boom', ['and size of bust in percent (R^2 = ' num2str(R_squared) ')']})
xlabel('Contribution of shock to price increase, 1996-2006') 
ylabel('Price drop 2012-2006') 
box on
